﻿<!-- 로그보기 -->
<!DOCTYPE html>
<html>
<body>


	<div id="logView" data-role="page" data-theme="a">
	<div data-role = "header">
		<a href="#" data-role="button" data-rel="back">이전</a>
		<h1>전단지</h1>
		<a href="#" data-role="button" id="del">지우기</a>
	</div>
	<div id="contentDiv" data-rol="content">
		<button onclick="getPhoto();">앨범에서 사진 선택</button>
		<div id="img">
		</div> 
		<hr/>
		<input type="text" name="o" class="input" id ="o"/>
		<input type="text" name="n" class="input" id ="n"/>
		<input type="tel" name="t" class="input" id ="t"/>
		<input type="text" name="m" class="input" id ="m"/>
		<input type="number" name="c" class="input" id ="c"/>
		<input type="text" name="mimetype" class="input" id ="mt" placeholder="분실일자" required="required"/>
		<input type="text" name="url" class="input" id ="mp" placeholder="분실장소" required="required" value="역삼동 멀티캠퍼스"/>
		<textarea name="payload" class="input" id="ms" placeholder="분실사유">분실사유</textarea>
		<textarea id="g" style="visibility:visible;"></textarea>
		
		<input id="pac-input" class="controls" type="text" style="width:200px" placeholder="동 이름을 검색">
		
		<div id="map_cvs" style="width: 100%; height: 240px;"></div>
		 
		 <button id="resetPath">Reset my path</button>
		 <button id="savePath">Save my path</button>
		<button onclick="sendPhoto();">찾아주세요! (SOS 발령)</button>
	</div>
	
	<script type="text/javascript">
		$('#logView').on('pageshow', function(){
			//url string
			var qString = fDecode(window.location.search.substring(1));
			var pid = fParamR('i', qString);
			$('#del').attr('onclick','fRemove('+pid+'); return false;'); 
			fRead(pid);
//			init();

			$('#mt').datetimepicker({
				 timepicker:false,
				 mask:true,
				 maxDate:0,
				 format:'Y/m/d' // '9999/19/39 29:59' - digit is the maximum possible for a cell
				});

		});

		/* 현재위치 가져오기 
	    var success = function(pos) {
	    	var currentLat = pos.coords.latitude;
	    	var currentLng = pos.coords.longitude;
	    	   var text = currentLat + ',' + currentLng + "\n";
	    	   alert('위치정보 확인 완료' + text);
	     	};
	    var fail = function(error) {
	    	alert('error occoured');
	        $("#cur_position").html("Error getting geolocation: " + error.code);
	        console.log("Error getting geolocation: code=" + error.code + " message=" + error.message);
	    };
		navigator.geolocation.getCurrentPosition(success, fail);
		 현재위치 가져오기 끝 */
		
		
		function onSuccess(position) {
		      currentLocation = position;
		      alert("onSuccess" + currentLocation);
		      if (!map) {
		         loadMapScript();
		      }
		   }
		   function onError(error) {
		      alert('code: ' + error.code + '\n' + 'message: ' + error.message + '\n');
		   }
/* 		var init = function(lat, lng) {
		      var latlng = new google.maps.LatLng(lat, lng);
		      var myOptions = {
		         zoom : 14,
		         center : latlng,
		         mapTypeId : google.maps.MapTypeId.ROADMAP
		      };
		      var map = new google.maps.Map(document.getElementById("map_cvs"), myOptions);
//		      vMap = map;
		      var infowindow = new google.maps.InfoWindow({
		         map : map,
		         position : latlng,
		         content : '자주 놀던 장소'
		      });
		      var marker = new google.maps.Marker({
		         map : map,
		         position : latlng,
		         icon : 'img/brown_MarkerA.png'
		      });
 		      navigator.geolocation.getCurrentPosition(onSuccess, onError);
		   };
 */
		
		function getPhoto(){
			navigator.camera.getPicture(
					function(imageURI){
						var image = document.getElementById('image');
						image.style.display = 'block';
						image.src = imageURI;
					},
					function(message){
						alert('Failed Because : ' + message);
					},
					{
						quality : 50,
						destinationType : navigator.camera.DestinationType.FILE_URI,
						sourceType : navigator.camera.PictureSourceType.SAVEDPHOTOALBUM
					}
			);
		}
		function sendPhoto(){
			var image = document.getElementById('image');
			var imageURI = image.src;
			//console.log(imageURI + "  <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
			var options = new FileUploadOptions();
			options.fileKey = "uploadImg";
			options.fileName = new Date().getTime();
			options.mimeType = "image/jpeg";
			var params = new Object();
			params.param0 = options.fileName;
			params.param1 = $("#o").val();
			params.param2 = $("#n").val();
			params.param3 = $("#t").val();
			params.param4 = $("#m").val();
			params.param5 = $("#c").val();
			params.param6 = $("#mt").val();
			params.param7 = $("#mp").val();
			params.param8 = $("#ms").val();
			params.param9 = $("#g").val();
			options.params = params;
			
			var fileTransfer = new FileTransfer();
			fileTransfer.upload(
				imageURI,
				"http://70.12.110.67:8888/upload",
				function(response){
					alert("Code = " + response.responseCode + "\n" + "Response = " + response.response + "\n" + "Sent = " + response.bytesSent	);
//					$.mobile.changePage( "http://70.12.110.62:8888/sosList", "slideleft" ); 
					$.mobile.changePage( "index.html", "slideleft" ); 
				},
				function(error){//1.앱사진파일문제,2.서버경로문제,3.연결문제
					alert("Error Code = " + error.code);
				},
				options
			);
		}
		
	</script>
</div>

</body>
</html>